/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jFPessoas.java
 *
 * Created on 05/04/2011, 00:39:39
 */

package sgfi;


import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import sgfi.Classes.Pessoas;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.JFormattedTextField;

import javax.swing.JOptionPane;
import javax.swing.JRootPane;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.JTextComponent;
import sgfi.Classes.ClassConecta;
import sgfi.Classes.ComboItem;
import sgfi.Classes.Comunidade;
import sgfi.Classes.Funcoes;
import sgfi.Classes.LivroCaixa;


/**
 *
 * @author Luciano Carrafa Benfica
 */
public class jFPessoas extends javax.swing.JFrame {

    /** Creates new form jFPessoas */
    public jFPessoas() {
        initComponents();
        JRootPane meurootpane = getRootPane();
        meurootpane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "ESCAPE");
        meurootpane.getRootPane().getActionMap().put("ESCAPE", new AbstractAction("ESCAPE") {

            public void actionPerformed(ActionEvent e) {
                setVisible(false);
            }
        });

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        buscarjButton = new javax.swing.JButton();
        novojButton = new javax.swing.JButton();
        editarjButton = new javax.swing.JButton();
        salvarjButton = new javax.swing.JButton();
        alterarjButton = new javax.swing.JButton();
        excluirjButton = new javax.swing.JButton();
        SairjButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        gradePessoasjTable = new javax.swing.JTable();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        painelCadastrojPanel = new javax.swing.JPanel();
        codPessoajSpinner = new javax.swing.JSpinner();
        jLabel1 = new javax.swing.JLabel();
        nomejTextField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        enderecojTextField = new javax.swing.JTextField();
        numerojTextField = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        bairrojTextField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        tipoDizimojComboBox = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        observacaojTextArea = new javax.swing.JTextArea();
        comunidadejComboBox = new javax.swing.JComboBox();
        atualizarjButton = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        cidadejTextField = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        ufjComboBox = new javax.swing.JComboBox();
        telefonejFormattedTextField = new javax.swing.JFormattedTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        emailjTextField = new javax.swing.JTextField();
        dataCadastrojFormattedTextField = new javax.swing.JFormattedTextField();
        jPanel3 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        gradeDizimojTable = new javax.swing.JTable();
        buscarLancamentosjButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sgfi.SGFIApp.class).getContext().getResourceMap(jFPessoas.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        buscarjButton.setIcon(resourceMap.getIcon("buscarjButton.icon")); // NOI18N
        buscarjButton.setText(resourceMap.getString("buscarjButton.text")); // NOI18N
        buscarjButton.setToolTipText(resourceMap.getString("buscarjButton.toolTipText")); // NOI18N
        buscarjButton.setFocusable(false);
        buscarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buscarjButton.setName("buscarjButton"); // NOI18N
        buscarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buscarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(buscarjButton);

        novojButton.setIcon(resourceMap.getIcon("novojButton.icon")); // NOI18N
        novojButton.setText(resourceMap.getString("novojButton.text")); // NOI18N
        novojButton.setToolTipText(resourceMap.getString("novojButton.toolTipText")); // NOI18N
        novojButton.setFocusable(false);
        novojButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        novojButton.setName("novojButton"); // NOI18N
        novojButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        novojButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                novojButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(novojButton);

        editarjButton.setIcon(resourceMap.getIcon("editarjButton.icon")); // NOI18N
        editarjButton.setText(resourceMap.getString("editarjButton.text")); // NOI18N
        editarjButton.setToolTipText(resourceMap.getString("editarjButton.toolTipText")); // NOI18N
        editarjButton.setFocusable(false);
        editarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        editarjButton.setName("editarjButton"); // NOI18N
        editarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        editarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(editarjButton);

        salvarjButton.setIcon(resourceMap.getIcon("salvarjButton.icon")); // NOI18N
        salvarjButton.setText(resourceMap.getString("salvarjButton.text")); // NOI18N
        salvarjButton.setToolTipText(resourceMap.getString("salvarjButton.toolTipText")); // NOI18N
        salvarjButton.setFocusable(false);
        salvarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        salvarjButton.setName("salvarjButton"); // NOI18N
        salvarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        salvarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(salvarjButton);

        alterarjButton.setIcon(resourceMap.getIcon("alterarjButton.icon")); // NOI18N
        alterarjButton.setText(resourceMap.getString("alterarjButton.text")); // NOI18N
        alterarjButton.setToolTipText(resourceMap.getString("alterarjButton.toolTipText")); // NOI18N
        alterarjButton.setFocusable(false);
        alterarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        alterarjButton.setName("alterarjButton"); // NOI18N
        alterarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        alterarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                alterarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(alterarjButton);

        excluirjButton.setIcon(resourceMap.getIcon("excluirjButton.icon")); // NOI18N
        excluirjButton.setText(resourceMap.getString("excluirjButton.text")); // NOI18N
        excluirjButton.setToolTipText(resourceMap.getString("excluirjButton.toolTipText")); // NOI18N
        excluirjButton.setFocusable(false);
        excluirjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        excluirjButton.setName("excluirjButton"); // NOI18N
        excluirjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        excluirjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                excluirjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(excluirjButton);

        SairjButton.setIcon(resourceMap.getIcon("SairjButton.icon")); // NOI18N
        SairjButton.setText(resourceMap.getString("SairjButton.text")); // NOI18N
        SairjButton.setToolTipText(resourceMap.getString("SairjButton.toolTipText")); // NOI18N
        SairjButton.setFocusable(false);
        SairjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        SairjButton.setName("SairjButton"); // NOI18N
        SairjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        SairjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SairjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(SairjButton);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel1.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), resourceMap.getColor("jPanel1.border.titleColor"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        gradePessoasjTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Nome", "Comunidade", "Telefone"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        gradePessoasjTable.setName("gradePessoasjTable"); // NOI18N
        gradePessoasjTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                gradePessoasjTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(gradePessoasjTable);
        gradePessoasjTable.getColumnModel().getColumn(0).setResizable(false);
        gradePessoasjTable.getColumnModel().getColumn(0).setPreferredWidth(80);
        gradePessoasjTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("gradePessoasjTable.columnModel.title0")); // NOI18N
        gradePessoasjTable.getColumnModel().getColumn(1).setResizable(false);
        gradePessoasjTable.getColumnModel().getColumn(1).setPreferredWidth(200);
        gradePessoasjTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("gradePessoasjTable.columnModel.title1")); // NOI18N
        gradePessoasjTable.getColumnModel().getColumn(2).setResizable(false);
        gradePessoasjTable.getColumnModel().getColumn(2).setPreferredWidth(250);
        gradePessoasjTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("gradePessoasjTable.columnModel.title2")); // NOI18N
        gradePessoasjTable.getColumnModel().getColumn(3).setResizable(false);
        gradePessoasjTable.getColumnModel().getColumn(3).setPreferredWidth(90);
        gradePessoasjTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("gradePessoasjTable.columnModel.title3")); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 693, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        painelCadastrojPanel.setName("painelCadastrojPanel"); // NOI18N

        codPessoajSpinner.setName("codPessoajSpinner"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        nomejTextField.setText(resourceMap.getString("nomejTextField.text")); // NOI18N
        nomejTextField.setName("nomejTextField"); // NOI18N
        nomejTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                nomejTextFieldKeyReleased(evt);
            }
        });

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        enderecojTextField.setText(resourceMap.getString("enderecojTextField.text")); // NOI18N
        enderecojTextField.setName("enderecojTextField"); // NOI18N

        numerojTextField.setText(resourceMap.getString("numerojTextField.text")); // NOI18N
        numerojTextField.setName("numerojTextField"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        bairrojTextField.setText(resourceMap.getString("bairrojTextField.text")); // NOI18N
        bairrojTextField.setName("bairrojTextField"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        tipoDizimojComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Individual", "Familiar" }));
        tipoDizimojComboBox.setName("tipoDizimojComboBox"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        observacaojTextArea.setColumns(20);
        observacaojTextArea.setRows(5);
        observacaojTextArea.setName("observacaojTextArea"); // NOI18N
        observacaojTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                observacaojTextAreaKeyTyped(evt);
            }
        });
        jScrollPane2.setViewportView(observacaojTextArea);

        comunidadejComboBox.setName("comunidadejComboBox"); // NOI18N

        atualizarjButton.setIcon(resourceMap.getIcon("atualizarjButton.icon")); // NOI18N
        atualizarjButton.setText(resourceMap.getString("atualizarjButton.text")); // NOI18N
        atualizarjButton.setName("atualizarjButton"); // NOI18N
        atualizarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atualizarjButtonActionPerformed(evt);
            }
        });

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        cidadejTextField.setText(resourceMap.getString("cidadejTextField.text")); // NOI18N
        cidadejTextField.setName("cidadejTextField"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        ufjComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "...", "AC", "AL", "AM", "AP", "BA", "CE", "DF", "ES", "GO", "MA", "MG", "MS", "MT", "PA", "PB", "PE", "PI", "PR", "RJ", "RN", "RO", "RR", "RS", "SC", "SE", "SP", "TO" }));
        ufjComboBox.setName("ufjComboBox"); // NOI18N

        try {
            telefonejFormattedTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##) ####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        telefonejFormattedTextField.setName("telefonejFormattedTextField"); // NOI18N

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        emailjTextField.setText(resourceMap.getString("emailjTextField.text")); // NOI18N
        emailjTextField.setName("emailjTextField"); // NOI18N

        dataCadastrojFormattedTextField.setFormatterFactory(Funcoes.setFormatoData());
        dataCadastrojFormattedTextField.setName("dataCadastrojFormattedTextField"); // NOI18N

        javax.swing.GroupLayout painelCadastrojPanelLayout = new javax.swing.GroupLayout(painelCadastrojPanel);
        painelCadastrojPanel.setLayout(painelCadastrojPanelLayout);
        painelCadastrojPanelLayout.setHorizontalGroup(
            painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelCadastrojPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelCadastrojPanelLayout.createSequentialGroup()
                        .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(enderecojTextField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, painelCadastrojPanelLayout.createSequentialGroup()
                                    .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(codPessoajSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel1))
                                    .addGap(18, 18, 18)
                                    .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(nomejTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel2))))
                            .addComponent(jLabel5)
                            .addGroup(painelCadastrojPanelLayout.createSequentialGroup()
                                .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(ufjComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel13))
                                .addGap(18, 18, 18)
                                .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(telefonejFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel14))
                                .addGap(18, 18, 18)
                                .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(tipoDizimojComboBox, 0, 93, Short.MAX_VALUE)
                                    .addComponent(jLabel8))))
                        .addGap(18, 18, 18)
                        .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(emailjTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE)
                            .addGroup(painelCadastrojPanelLayout.createSequentialGroup()
                                .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addGroup(painelCadastrojPanelLayout.createSequentialGroup()
                                        .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(numerojTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel6))
                                        .addGap(18, 18, 18)
                                        .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(bairrojTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
                                            .addComponent(jLabel7)))
                                    .addComponent(comunidadejComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(painelCadastrojPanelLayout.createSequentialGroup()
                                        .addComponent(atualizarjButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addGroup(painelCadastrojPanelLayout.createSequentialGroup()
                                                .addComponent(jLabel4)
                                                .addGap(9, 9, 9))
                                            .addComponent(dataCadastrojFormattedTextField)))
                                    .addComponent(jLabel12)
                                    .addComponent(cidadejTextField)))
                            .addComponent(jLabel15)))
                    .addComponent(jLabel9)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 697, Short.MAX_VALUE))
                .addGap(33, 33, 33))
        );
        painelCadastrojPanelLayout.setVerticalGroup(
            painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelCadastrojPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(painelCadastrojPanelLayout.createSequentialGroup()
                        .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(codPessoajSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(nomejTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(comunidadejComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(dataCadastrojFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(atualizarjButton))
                .addGap(18, 18, 18)
                .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enderecojTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(numerojTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bairrojTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cidadejTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(painelCadastrojPanelLayout.createSequentialGroup()
                        .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(jLabel14))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ufjComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(telefonejFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(painelCadastrojPanelLayout.createSequentialGroup()
                        .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(jLabel15))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(painelCadastrojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tipoDizimojComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(emailjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(45, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("painelCadastrojPanel.TabConstraints.tabTitle"), painelCadastrojPanel); // NOI18N

        jPanel3.setName("jPanel3"); // NOI18N

        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel5.setName("jPanel5"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        gradeDizimojTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Código", "Nome", "Histórico", "Data Lançamento", "Valor"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Float.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        gradeDizimojTable.setName("gradeDizimojTable"); // NOI18N
        jScrollPane3.setViewportView(gradeDizimojTable);
        gradeDizimojTable.getColumnModel().getColumn(0).setResizable(false);
        gradeDizimojTable.getColumnModel().getColumn(0).setPreferredWidth(40);
        gradeDizimojTable.getColumnModel().getColumn(1).setResizable(false);
        gradeDizimojTable.getColumnModel().getColumn(1).setPreferredWidth(150);
        gradeDizimojTable.getColumnModel().getColumn(2).setResizable(false);
        gradeDizimojTable.getColumnModel().getColumn(2).setPreferredWidth(150);
        gradeDizimojTable.getColumnModel().getColumn(3).setResizable(false);
        gradeDizimojTable.getColumnModel().getColumn(3).setPreferredWidth(80);
        gradeDizimojTable.getColumnModel().getColumn(4).setResizable(false);
        gradeDizimojTable.getColumnModel().getColumn(4).setPreferredWidth(80);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 676, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE)
                .addContainerGap())
        );

        buscarLancamentosjButton.setIcon(resourceMap.getIcon("buscarLancamentosjButton.icon")); // NOI18N
        buscarLancamentosjButton.setText(resourceMap.getString("buscarLancamentosjButton.text")); // NOI18N
        buscarLancamentosjButton.setName("buscarLancamentosjButton"); // NOI18N
        buscarLancamentosjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarLancamentosjButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(buscarLancamentosjButton))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addComponent(buscarLancamentosjButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel3.TabConstraints.tabTitle"), jPanel3); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 745, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 725, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents



    public ClassConecta conexao = new ClassConecta();

    ComboItem comboComunidade;
    
    public int codPessoa;


    protected  static void limpaCampos(Container container){

         for(Component component : container.getComponents()) {
             if((component instanceof JTextField) || (component instanceof JFormattedTextField)) {
                 ((JTextComponent)component).setText("");

             } else if (component instanceof JScrollPane) {
                 ((JTextArea) ((JScrollPane) component).getViewport().getComponent(0)).setText("");
             }
                else if (component instanceof JSpinner){
                 ((JSpinner)component).setValue(0);
                 
             }
         }
     }


      public void getGrandePessoa() throws ParseException{
       //Consultar pedidos
        Pessoas oPessoa = new Pessoas();

        if ( nomejTextField.getText().length() > 0 ){
            oPessoa.setPessoa(nomejTextField.getText()+"%");
        }

        ResultSet resultSet = null;

        String[] colunasTabela = new String[]{"Código", "Nome", "Comunidade", "Telefone"};
        DefaultTableModel modeloTabela = new DefaultTableModel(null, colunasTabela) {

            @Override
            public boolean isCellEditable(int row, int col) {
                return false;
            }
        };
        gradePessoasjTable.setModel(modeloTabela);
        gradePessoasjTable.getColumnModel().getColumn(0).setPreferredWidth(50);
        gradePessoasjTable.getColumnModel().getColumn(1).setPreferredWidth(200);
        gradePessoasjTable.getColumnModel().getColumn(2).setPreferredWidth(300);
        gradePessoasjTable.getColumnModel().getColumn(3).setPreferredWidth(90);



try {


            resultSet = oPessoa.getConsultar();
           
            if (resultSet.getRow() == 1){
             resultSet.first();
            }


        } catch (SQLException ex) {
            Logger.getLogger(Pessoas.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            while (resultSet.next()) {

                modeloTabela.addRow(new String[]{
                    Funcoes.getCodigoFormat(resultSet.getInt("codPessoa")),
                    resultSet.getString("Pessoa"),
                    resultSet.getString("NomeComunidade") ,
                    resultSet.getString("telefone"),
                });

            }

        } catch (SQLException ex) {
            Logger.getLogger(Comunidade.class.getName()).log(Level.SEVERE, null, ex);
        }

           }

    public void getGradeDizimo() throws ParseException{
       //Consultar lançamentos do caixa de acordo com o código da pessoa selecionada na tabela
        LivroCaixa oLivro_Caixa = new LivroCaixa();

        ResultSet resultSet = null;

        String[] colunasTabela = new String[]{"Código", "Nome", "Histórico", "Data Lançamento", "Valor"};
        DefaultTableModel modeloTabela = new DefaultTableModel(null, colunasTabela) {

            @Override
            public boolean isCellEditable(int row, int col) {
                return false;
            }
        };
        gradeDizimojTable.setModel(modeloTabela);
        gradeDizimojTable.getColumnModel().getColumn(0).setPreferredWidth(40);
        gradeDizimojTable.getColumnModel().getColumn(1).setPreferredWidth(150);
        gradeDizimojTable.getColumnModel().getColumn(2).setPreferredWidth(150);
        gradeDizimojTable.getColumnModel().getColumn(3).setPreferredWidth(80);
        gradeDizimojTable.getColumnModel().getColumn(4).setPreferredWidth(80);


try {
            oLivro_Caixa.setCodPessoa(codPessoa);

            resultSet = oLivro_Caixa.getConsultarLancamentos();

        } catch (SQLException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            while (resultSet.next()) {

                //Formatar valor
                DecimalFormat valorLancamento = new DecimalFormat("###,###,##0.00");
                String oValorLancamento = null;
                if (resultSet.getFloat("valor") > 0) {
                    oValorLancamento = valorLancamento.format(resultSet.getFloat("valor"));
                } else {
                    oValorLancamento = null;
                }
                //Fim formataç?o

                String codLancamentoFormatado = null;
                DecimalFormat formatoCodigo = new DecimalFormat("00000");
                codLancamentoFormatado = formatoCodigo.format(resultSet.getInt("codLanc"));

                //Formatar data
                Date vencimento = resultSet.getDate("dataLanc");

                String dataLanc = null;
                if (vencimento != null){
                SimpleDateFormat formatoDataLanc = new SimpleDateFormat("dd/MM/yyyy");
                dataLanc = formatoDataLanc.format(vencimento);
                }else{
                dataLanc = "";
                }
                //Fim formataç?o

                modeloTabela.addRow(new String[]{
                    codLancamentoFormatado,
                    resultSet.getString("pessoa"),
                    resultSet.getString("historico"),
                    dataLanc,
                    oValorLancamento

                });

            }

        } catch (SQLException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

        public void getFieldPessoa(int codPessoa) throws ParseException{

        Pessoas oPessoa = new Pessoas();
        ResultSet rs = null;
        oPessoa.setCodPessoa(codPessoa);

        try {
            rs = oPessoa.getConsultar();
            rs.next();

            ComboItem oItem = new ComboItem(rs.getInt("codComunidade"), rs.getString("nomeComunidade"));
            comunidadejComboBox.setSelectedItem(oItem);
            //Pegar campos
            codPessoajSpinner.setValue(rs.getInt("codPessoa"));
            nomejTextField.setText(rs.getString("pessoa"));
            dataCadastrojFormattedTextField.setValue(Funcoes.getDataFormat(rs.getDate("dataCadastro")));
            enderecojTextField.setText(rs.getString("endereco"));
            numerojTextField.setText(rs.getString("numero"));
            bairrojTextField.setText(rs.getString("bairro"));
            cidadejTextField.setText(rs.getString("cidade"));
            ufjComboBox.setSelectedItem(rs.getString("uf"));
            tipoDizimojComboBox.setSelectedItem(rs.getString("tipoDizimo"));
            telefonejFormattedTextField.setText(rs.getString("telefone"));
            emailjTextField.setText(rs.getString("email"));
            observacaojTextArea.setText(rs.getString("observacao"));

        } catch (SQLException ex) {
            Logger.getLogger(Pessoas.class.getName()).log(Level.SEVERE, null, ex);
        }



    }



    private void SairjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SairjButtonActionPerformed
        // TODO add your handling code here:
         if (salvarjButton.isEnabled()){
            Object[] options = {"Sim", "Não"};
        int sd =
                JOptionPane.showOptionDialog(
                null,
                "Deseja realmente Sair sem salvar?\nAs informações não salvas serão perdidas!",
                "Confirmação!",
                JOptionPane.DEFAULT_OPTION,
                JOptionPane.WARNING_MESSAGE,
                null,
                options,
                options[0]);

        if (sd != 0) {
            return;
        }
        this.dispose();

        }else{
            this.dispose();
        }
    }//GEN-LAST:event_SairjButtonActionPerformed

    private void atualizarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atualizarjButtonActionPerformed
        try {
            // TODO add your handling code here:
            Comunidade oComunidade = new Comunidade();
            ResultSet rs = null;
            rs = oComunidade.getConsultar();
            comunidadejComboBox.removeAllItems();
            while (rs.next()) {
                comunidadejComboBox.addItem(new ComboItem(rs.getInt(1), rs.getString(2)));
            }
            comunidadejComboBox.updateUI();
        } catch (SQLException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_atualizarjButtonActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here
        ClassConecta.conecta();
        atualizarjButtonActionPerformed(null);
        buscarjButtonActionPerformed(null);
        setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage("igreja.png"));



        try {
            dataCadastrojFormattedTextField.setText(Funcoes.getNowBR());
        } catch (ParseException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }

                    salvarjButton.setEnabled(false);
                    alterarjButton.setEnabled(false);
                    excluirjButton.setEnabled(false);
                    editarjButton.setEnabled(false);
                    novojButton.setEnabled(true);

                    nomejTextField.grabFocus();

                    ufjComboBox.setSelectedItem("ES");


       

    }//GEN-LAST:event_formWindowOpened

    private void novojButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novojButtonActionPerformed
        // TODO add your handling code here:
        novojButton.setEnabled(false);
        alterarjButton.setEnabled(false);
        editarjButton.setEnabled(false);
        excluirjButton.setEnabled(false);
        buscarjButton.setEnabled(true);
        salvarjButton.setEnabled(true);
        codPessoajSpinner.setEnabled(false);
        nomejTextField.grabFocus();
        try {
            ClassConecta.con.setAutoCommit(false);
        } catch (SQLException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }


            limpaCampos(painelCadastrojPanel);
            ufjComboBox.setSelectedItem("ES");
            tipoDizimojComboBox.setSelectedItem("Individual");
          
        try {
            dataCadastrojFormattedTextField.setText(Funcoes.getNowBR());
        } catch (ParseException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_novojButtonActionPerformed

    private void salvarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarjButtonActionPerformed
        try {
            // TODO add your handling code here:
            salvarjButton.setEnabled(false);
            alterarjButton.setEnabled(false);
            excluirjButton.setEnabled(false);
            novojButton.setEnabled(true);
            editarjButton.setEnabled(true);
            comboComunidade = (ComboItem) comunidadejComboBox.getSelectedItem();
            Pessoas oPessoa = new Pessoas();

            oPessoa.setPessoa(nomejTextField.getText());
            oPessoa.setCodComunidade(comboComunidade.getId());
            oPessoa.setEndereco(enderecojTextField.getText());
            oPessoa.setNumero(numerojTextField.getText());
            oPessoa.setBairro(bairrojTextField.getText());
            oPessoa.setCidade(cidadejTextField.getText());
            oPessoa.setUf(ufjComboBox.getSelectedItem().toString());
            oPessoa.setTelefone(telefonejFormattedTextField.getText());
            oPessoa.setTipoDizimo(tipoDizimojComboBox.getSelectedItem().toString());
            oPessoa.setEmail(emailjTextField.getText());
            oPessoa.setObservacao(observacaojTextArea.getText());
            oPessoa.setDataCadastro(Funcoes.getDataFormatBR(dataCadastrojFormattedTextField.getText()));
            

            oPessoa.setCadastrar();

            getGrandePessoa();

            ClassConecta.con.commit();
            ClassConecta.con.setAutoCommit(true);
            
            int cod_pessoa = oPessoa.getId();
            Funcoes.getItemJTable(cod_pessoa, gradePessoasjTable);
            ufjComboBox.setSelectedItem("ES");
            tipoDizimojComboBox.setSelectedItem("Individual");

        } catch (ParseException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }


    }//GEN-LAST:event_salvarjButtonActionPerformed

    private void buscarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarjButtonActionPerformed
        try {
            // TODO add your handling code here:
            getGrandePessoa();
        } catch (ParseException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buscarjButtonActionPerformed

    private void gradePessoasjTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gradePessoasjTableMouseClicked
        // TODO add your handling code here:
            editarjButton.setEnabled(true);
            codPessoa = Integer.parseInt(gradePessoasjTable.getValueAt(gradePessoasjTable.getSelectedRow(), 0).toString());
            if (codPessoa == 0) {
                return;
            }
        try {
            getFieldPessoa(codPessoa);
            getGradeDizimo();
        } catch (ParseException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_gradePessoasjTableMouseClicked

    private void nomejTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nomejTextFieldKeyReleased
        // TODO add your handling code here:
                if (!alterarjButton.isEnabled()){
            try {
                Pessoas oPessoa = new Pessoas();
                oPessoa.setPessoa(nomejTextField.getText());
                ResultSet rs = null;
                rs = oPessoa.getConsultar();
                getGrandePessoa();
            } catch (ParseException ex) {
                Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
                    }
    }
                if(nomejTextField.getText().equals("")){
            nomejTextField.setText("");
            enderecojTextField.setText("");
            numerojTextField.setText("");
            bairrojTextField.setText("");
            cidadejTextField.setText("");
            ufjComboBox.setSelectedItem("ES");
            telefonejFormattedTextField.setText("");
            tipoDizimojComboBox.setSelectedItem("Individual");
            emailjTextField.setText("");
            observacaojTextArea.setText("");
            codPessoajSpinner.setValue(0);
            try {
                dataCadastrojFormattedTextField.setText(Funcoes.getNowBR());
            } catch (ParseException ex) {
                Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
            }
                }
    }//GEN-LAST:event_nomejTextFieldKeyReleased

    private void alterarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_alterarjButtonActionPerformed
        try {
            // TODO add your handling code here:
            alterarjButton.setEnabled(false);
            editarjButton.setEnabled(true);
            excluirjButton.setEnabled(false);
            novojButton.setEnabled(true);
            comboComunidade = (ComboItem) comunidadejComboBox.getSelectedItem();
            @SuppressWarnings(value = "LocalVariableHidesMemberVariable")
           
            int codPessoa = 0;
            codPessoa = Integer.parseInt(gradePessoasjTable.getValueAt(gradePessoasjTable.getSelectedRow(), 0).toString());
            
            Pessoas oPessoa = new Pessoas();
            oPessoa.setCodPessoa(codPessoa);

            oPessoa.setPessoa(nomejTextField.getText());
            oPessoa.setCodComunidade(comboComunidade.getId());
            oPessoa.setEndereco(enderecojTextField.getText());
            oPessoa.setNumero(numerojTextField.getText());
            oPessoa.setBairro(bairrojTextField.getText());
            oPessoa.setCidade(cidadejTextField.getText());
            oPessoa.setUf(ufjComboBox.getSelectedItem().toString());
            oPessoa.setTelefone(telefonejFormattedTextField.getText());
            oPessoa.setTipoDizimo(tipoDizimojComboBox.getSelectedItem().toString());
            oPessoa.setEmail(emailjTextField.getText());
            oPessoa.setObservacao(observacaojTextArea.getText());
            oPessoa.setDataCadastro(Funcoes.getDataFormatBR(dataCadastrojFormattedTextField.getText()));
            oPessoa.setAlterar(conexao);

            getGrandePessoa();

            try {
                ClassConecta.con.commit();
                ClassConecta.con.setAutoCommit(true);

            Funcoes.getItemJTable(codPessoa, gradePessoasjTable);

            } catch (SQLException ex) {
                Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
            }



        } catch (ParseException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_alterarjButtonActionPerformed

    private void editarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editarjButtonActionPerformed
        // TODO add your handling code here:
            novojButton.setEnabled(false);
            salvarjButton.setEnabled(false);
            editarjButton.setEnabled(false);
            alterarjButton.setEnabled(true);
            excluirjButton.setEnabled(true);
        try {
            ClassConecta.con.setAutoCommit(false);
        } catch (SQLException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_editarjButtonActionPerformed

    private void observacaojTextAreaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_observacaojTextAreaKeyTyped
        // TODO add your handling code here:
        observacaojTextArea.setLineWrap(true);
        observacaojTextArea.setWrapStyleWord(true);
    }//GEN-LAST:event_observacaojTextAreaKeyTyped

    private void excluirjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_excluirjButtonActionPerformed
        // TODO add your handling code here:
         Object[] options = {"Sim", "Não"};
        int sd =
                JOptionPane.showOptionDialog(
                null,
                "Deseja realmente EXCLUIR esse registro?",
                "Confirmação!",
                JOptionPane.DEFAULT_OPTION,
                JOptionPane.WARNING_MESSAGE,
                null,
                options,
                options[0]);

        if (sd != 0) {
            return;
        }
        alterarjButton.setEnabled(false);
        editarjButton.setEnabled(true);
        excluirjButton.setEnabled(false);
        novojButton.setEnabled(true);

        int codPessoaDelete = 0;
        codPessoaDelete = Integer.parseInt(gradePessoasjTable.getValueAt(gradePessoasjTable.getSelectedRow(), 0).toString());

        Pessoas oPessoa = new Pessoas();
        oPessoa.setCodPessoa(codPessoaDelete);
        oPessoa.setExcluir(conexao);
        try {
            ClassConecta.con.commit();
            ClassConecta.con.setAutoCommit(true);
        } catch (SQLException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }

            limpaCampos(painelCadastrojPanel);
            ufjComboBox.setSelectedItem("ES");
            tipoDizimojComboBox.setSelectedItem("Individual");
        try {
            dataCadastrojFormattedTextField.setText(Funcoes.getNowBR());
            getGrandePessoa();
        } catch (ParseException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }


    }//GEN-LAST:event_excluirjButtonActionPerformed

    private void buscarLancamentosjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarLancamentosjButtonActionPerformed
        try {
            // TODO add your handling code here:
            getGradeDizimo();
        } catch (ParseException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buscarLancamentosjButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jFPessoas().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton SairjButton;
    private javax.swing.JButton alterarjButton;
    private javax.swing.JButton atualizarjButton;
    private javax.swing.JTextField bairrojTextField;
    private javax.swing.JButton buscarLancamentosjButton;
    private javax.swing.JButton buscarjButton;
    private javax.swing.JTextField cidadejTextField;
    private javax.swing.JSpinner codPessoajSpinner;
    private javax.swing.JComboBox comunidadejComboBox;
    private javax.swing.JFormattedTextField dataCadastrojFormattedTextField;
    private javax.swing.JButton editarjButton;
    private javax.swing.JTextField emailjTextField;
    private javax.swing.JTextField enderecojTextField;
    private javax.swing.JButton excluirjButton;
    private javax.swing.JTable gradeDizimojTable;
    private javax.swing.JTable gradePessoasjTable;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTextField nomejTextField;
    private javax.swing.JButton novojButton;
    private javax.swing.JTextField numerojTextField;
    private javax.swing.JTextArea observacaojTextArea;
    private javax.swing.JPanel painelCadastrojPanel;
    private javax.swing.JButton salvarjButton;
    private javax.swing.JFormattedTextField telefonejFormattedTextField;
    private javax.swing.JComboBox tipoDizimojComboBox;
    private javax.swing.JComboBox ufjComboBox;
    // End of variables declaration//GEN-END:variables

}
